package com.huitone.gddw.service.impl.analysis.invaliduser;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huitone.gddw.dao.analysis.invaliduser.IInvalidUserRepDao;
import com.huitone.gddw.dao.entity.InvalidUse;
import com.huitone.gddw.model.support.QueryPage;
import com.huitone.gddw.service.analysis.invaliduser.IInvalidUserRepService;
import com.huitone.gddw.service.dto.analysis.invaliduser.InvalidUserRecDTO;
import com.huitone.gddw.service.dto.analysis.invaliduser.InvalidUserRepACDTO;
import com.huitone.gddw.service.dto.analysis.invaliduser.InvalidUserRepDTO;
import com.huitone.gddw.service.dto.analysis.invaliduser.NumActivationRecDTO;

/**
 * 无效用户分析 接口实现类
 * 
 * @author chengsiyue
 *
 */
@Service
public class InvalidUserRepService implements IInvalidUserRepService {

	@Autowired
	private IInvalidUserRepDao invalidUserRepDao;

	@Override
	public QueryPage<InvalidUserRepDTO> selectPage(QueryPage<InvalidUse> page) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("startDate", page.getParams().get("startDate"));
		map.put("endDate", page.getParams().get("endDate"));
		map.put("desc", page.getParams().get("desc"));
		
		List<InvalidUserRepDTO> result = invalidUserRepDao.selectPage(map);
		QueryPage<InvalidUserRepDTO> queryPage = new QueryPage<InvalidUserRepDTO>();
		queryPage.setResult(result);
		queryPage.setObj(this.getTotal(map));
		return queryPage;
	}

	@Override
	public List<InvalidUserRepDTO> getRecord(Map<String, Object> map) {
		return invalidUserRepDao.getRecord(map);
	}

	@Override
	public InvalidUserRepACDTO getTotal(Map<String, Object> map) {
		long total = invalidUserRepDao.getTotal(map);
		InvalidUserRepACDTO invalidUserRepACDTO = new InvalidUserRepACDTO();
		invalidUserRepACDTO.setInvalidCount(total);
		return invalidUserRepACDTO;
	}

	@Override
	public QueryPage<InvalidUserRecDTO> selectDetial(QueryPage<InvalidUse> page) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("startDate", page.getParams().get("startDate"));
		map.put("endDate", page.getParams().get("endDate"));
		map.put("failReason", page.getParams().get("failReason"));
		
		map.put("newInvalidNum", page.getParams().get("newInvalidNum"));
		map.put("delInvalidNum", page.getParams().get("delInvalidNum"));
		map.put("invalidCount", page.getParams().get("invalidCount"));
		
		map.put("start", (page.getPageNo() - 1) * page.getPageSize()+1);
		map.put("end", (page.getPageNo() - 1) * page.getPageSize() + page.getPageSize());

		List<InvalidUserRecDTO> result = invalidUserRepDao.selectDetial(map);
		QueryPage<InvalidUserRecDTO> queryPage = new QueryPage<InvalidUserRecDTO>();
		queryPage.setResult(result);
		
		long total = invalidUserRepDao.getTotal(map);
		int totalCount =  invalidUserRepDao.selectCount(map);
		InvalidUserRepACDTO invalidUserRepACDTO = new InvalidUserRepACDTO();
		invalidUserRepACDTO.setInvalidCount(total);
		queryPage.setPageNo(page.getPageNo());
		queryPage.setPageSize(page.getPageSize());
		queryPage.setTotalCount(totalCount);
		queryPage.setObj(invalidUserRepACDTO);
		return queryPage;
	}

	@Override
	public List<InvalidUserRecDTO> getRecordDetial(Map<String, Object> map) {

		return invalidUserRepDao.getRecordDetial(map);
	}

	@Override
	public QueryPage<NumActivationRecDTO> getNumActivationRec(QueryPage<InvalidUse> page) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("startDate", page.getParams().get("startDate"));
		map.put("endDate", page.getParams().get("endDate"));
		
		map.put("start", (page.getPageNo() - 1) * page.getPageSize()+1);
		map.put("end", (page.getPageNo() - 1) * page.getPageSize() + page.getPageSize());
		
		List<NumActivationRecDTO> result = invalidUserRepDao.getNumActivationRec(map);
		long totalCount = invalidUserRepDao.selectNumActCount(map);
		QueryPage<NumActivationRecDTO> queryPage = new QueryPage<NumActivationRecDTO>();
		queryPage.setResult(result);
		queryPage.setPageNo(page.getPageNo());
		queryPage.setPageSize(page.getPageSize());
		queryPage.setTotalCount(totalCount);
		return queryPage;
	}

	@Override
	public List<NumActivationRecDTO> getNumActRecord(Map<String, Object> map) {
		return invalidUserRepDao.getNumActRecord(map);
	}

	@Override
	public QueryPage<InvalidUserRecDTO> detailPage(QueryPage<?> page) {
		// TODO Auto-generated method stub
		return null;
	}

}
